package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.AppUserPrivatedata;
import com.meida.module.bus.client.entity.BusAirport;
import com.meida.module.bus.client.enums.IdentityTypeEnum;
import com.meida.module.bus.client.enums.RegisterWayEnum;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 用户详情扩展
 *
 * @author gp
 */
@Component
public class AppUserInfoHandler implements GetInterceptor {

    @Override
    public void prepare(CriteriaQuery cq, EntityMap params) {
        cq.clear();
        cq.select(AppUser.class, "userId", "userNo", "userName", "openId", "status", "registerWay", "mobile", "privateDataId");
        cq.select(AppUserPrivatedata.class, "userName", "mobile", "telePhone", "identityType", "identityNo");
        cq.select(BusAirport.class, "airportName");
        cq.createJoin(AppUserPrivatedata.class);
        cq.createJoin(BusAirport.class);

    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Integer registerWay = map.getInt("registerWay");
        map.put("registerWayLabel", "");
        RegisterWayEnum registerWayEnum = RegisterWayEnum.getByValue(registerWay);
        if (FlymeUtils.isNotEmpty(registerWayEnum)) {
            String registerWayLabel = registerWayEnum.getLabel();
            map.put("registerWayLabel", registerWayLabel);
        }
        Integer identityType = map.getInt("identityType");
        IdentityTypeEnum identityTypeEnum = IdentityTypeEnum.getByValue(identityType);
        if (FlymeUtils.isNotEmpty(identityTypeEnum)) {
            String identityTypeDesc = identityTypeEnum.getLabel();
            map.put("identityTypeDesc", identityTypeDesc);
        }
    }
}
